package com.ebookstore.service.impl;

import java.util.List;

import com.ebookstore.dao.BaseDAO;
import com.ebookstore.dto.Book;
import com.ebookstore.dto.Bookview;
import com.ebookstore.service.BookService;

public class BookServiceImpl implements BookService {

	private static final String BOOK_NAME = "bookName";
	private static final String AUTHOR = "author";
	
	private static final BaseDAO bookDao = new BaseDAO();

	public BookServiceImpl() {
		super();
	}
	
	public List<Book> findBookByKeyword(String keyword) {
		if ("*".equals(keyword)){
			return bookDao.findByHql("from Book");
		}
		StringBuffer strhql = new StringBuffer("from Book where ");
		strhql.append(BOOK_NAME).append(" like '%" + keyword + "%' or ");
		strhql.append(AUTHOR).append(" like '%" + keyword + "%'");
		return bookDao.findByHql(strhql.toString());
	}

	public List<Bookview> findBookByPublishDate() {
		return bookDao.findByHql("from Bookview  order by publishDate", -1, 6);
	}
	public List findCategory() {
		return bookDao.findByHql("from Category");
	}

	public List<Bookview> findBookByCategory(String categoryId) {
		return bookDao.findByHql("from Bookview where categoryId=" + categoryId);
	}

}
